//
//  DeleUploadImage.m
//  A段项目
//
//  Created by dllo on 16/1/27.
//  Copyright © 2016年 Scott. All rights reserved.
//

#import "DeleUploadImage.h"

@interface DeleUploadImage ()

@property (nonatomic, retain) UIImageView *imageViewUp;

@end

@implementation DeleUploadImage

- (void)dealloc {
    
    [_image release];
    [_imageViewUp release];
    
    [super dealloc];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor blackColor];
    
   self.imageViewUp = [[UIImageView alloc] initWithImage:self.image];
    
    [self.view addSubview:self.imageViewUp]; //添加 imageView
    
    self.imageViewUp.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height/1.5);
    
    
    self.imageViewUp.center = self.view.center;
    
    [_imageViewUp release];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    
    button.frame = CGRectMake(0, self.view.frame.size.height - 60, self.view.bounds.size.width, 60);
    
    [self.view addSubview:button];   //添加删除按钮
    
    [button setImage:[UIImage imageNamed:@"dele"] forState:UIControlStateNormal];
    
    button.tintColor = [UIColor whiteColor];
    
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
}


- (void) buttonAction:(UIButton *)button {
    
    NSFileManager *fileManger = [NSFileManager defaultManager];
    
    /** 读取图片路径. */
    NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject]stringByAppendingPathComponent:@"image.png"];
    
    [fileManger removeItemAtPath:filePath error:nil]; //删除图片
    
    [self.delegate deleteImage:self.image]; //此时执行代理方法.
    
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
    
}

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
